Decomposition¶

Hurdles 👩🏼‍🎨¶

  • What pattern or strategy best fits this problem?
  • What verbs would make this problem easy to solve?

NOTES

The event stream pattern works well: the event is running into a jumpable wall (left clear). The event loop runs until Bit cannot jump anymore.

  • You can also use "up" and "drop" as events with an if/else as opposed to a single "jump hurdle" event
    • But this is a bit tricky: the order of conditions is critical
  • Note that "up" and "over" are similar, vs "down"

Elevators 👨🏼‍🎨¶

elevators.py¶

Bit needs to climb to the top of the building, using the green elevators.

NOTES

This activity prepares the students for waterfall.py in the lab.

  • Draw it out!
  • Pose the problem as an event stream problem
  • What is the outer loop?
  • What is the condition that triggers the event?
    • What is the event?
  • How do we rise?
    • What is the while condition?
    • What is the glue code before and after the "rise" loop?
  • Use comments to indicate subgoals

More Elevators¶

Now write a single function that can allow Bit to travel in either direction.

NOTES

Add in 'more-elevators' as a test case. Observe the problem: Bit turns into the floor when heading from left to right.

How do we know which way to turn to rise?

Similar "rise" blocks: each has a while loop, but the turns are different.

Key Ideas¶

  • abstraction: create the pieces that will solve the problem
  • boundary conditions: knowing how the pieces fit together